####损失函数：均方误差
import numpy as np


def mean_squared_error(y,t):
    return 0.5 * np.sum((y - t) ** 2)


if __name__ == '__main__':
    t = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]  #监督数据
    print("----设 2 为正确解----")
    y = [0.1,0.05,0.6,0.0,0.05,0.1,0.0,0.1,0.0,0.0]  #神经网络输出
    a = mean_squared_error(np.array(y),np.array(t))  #使用均方误差函数查看输入数据与监督数据之间的损失函数值
    print(a)  #0.09750000000000003  #接近1
    print("----当2为正确解，但是神经网络输出结果判断定7概率最高时")
    y_1 = [0.1,0.05,0.1,0.0,0.05,0.1,0.0,0.6,0.0,0.0]  #神经网络输出
    a_1 = mean_squared_error(np.array(y_1),np.array(t))  #使用均方误差函数查看输入数据与监督数据之间的损失函数值
    print(a_1)  #0.5975,与数值1差距较大

